package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SocDispatchEmpLessAddDTO;
import org.jsola.hr.dto.SocDispatchEmpLessUpdateDTO;
import org.jsola.hr.entity.SocDispatchEmpLessDO;
import org.jsola.hr.query.SocDispatchEmpLessQuery;
import org.jsola.hr.service.ISocDispatchEmpLessService;
import org.jsola.hr.vo.SocDispatchEmpLessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 社保派单员工表_减员
 *
 * @author zhr
 */
@Component
public class SocDispatchEmpLessTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISocDispatchEmpLessService socDispatchEmpLessService;

    /**
     * 生成add测试数据
     * @return SocDispatchEmpLessAddDTO
     */
    public SocDispatchEmpLessAddDTO getSocDispatchEmpLessAddDTO(){
        SocDispatchEmpLessAddDTO socDispatchEmpLessAddDTO = new SocDispatchEmpLessAddDTO();
        socDispatchEmpLessAddDTO.setSocDispatchId(getRandomValue("varchar",32));
        socDispatchEmpLessAddDTO.setYear(getRandomValue("varchar",12));
        socDispatchEmpLessAddDTO.setMonth(getRandomValue("varchar",10));
        socDispatchEmpLessAddDTO.setName(getRandomValue("varchar",50));
        socDispatchEmpLessAddDTO.setPhone(getRandomValue("varchar",20));
        socDispatchEmpLessAddDTO.setIdCard(getRandomValue("varchar",32));
        socDispatchEmpLessAddDTO.setSocCityName(getRandomValue("varchar",100));
        socDispatchEmpLessAddDTO.setSocCityId(SafeKit.getLong(getRandomValue("bigint",11)));
        socDispatchEmpLessAddDTO.setAssignCompanyId(getRandomValue("varchar",32));
        socDispatchEmpLessAddDTO.setAssignCompanyName(getRandomValue("varchar",100));
        socDispatchEmpLessAddDTO.setSocEndDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        socDispatchEmpLessAddDTO.setFundEndDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        socDispatchEmpLessAddDTO.setQuitDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        socDispatchEmpLessAddDTO.setReasonQuit(getRandomValue("text",2147483647));
        socDispatchEmpLessAddDTO.setRemake(getRandomValue("text",2147483647));
        socDispatchEmpLessAddDTO.setStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        socDispatchEmpLessAddDTO.setHasSend(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socDispatchEmpLessAddDTO.setHasReceive(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socDispatchEmpLessAddDTO.setNoError(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socDispatchEmpLessAddDTO.setCompanyId(getRandomValue("varchar",32));
        socDispatchEmpLessAddDTO.setSort(SafeKit.getInteger(getRandomValue("bigint",11)));
        return socDispatchEmpLessAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SocDispatchEmpLessUpdateDTO
     */
    public SocDispatchEmpLessUpdateDTO getSocDispatchEmpLessUpdateDTO(SocDispatchEmpLessVO socDispatchEmpLessVO){
        return socDispatchEmpLessService.selectDOById(socDispatchEmpLessVO.getId(), SITE_ID).to(SocDispatchEmpLessUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SocDispatchEmpLessQuery
     */
    public SocDispatchEmpLessQuery getSocDispatchEmpLessQuery() {
        SocDispatchEmpLessQuery socDispatchEmpLessQuery = new SocDispatchEmpLessQuery();
        List<SocDispatchEmpLessDO> socDispatchEmpLessDOList = socDispatchEmpLessService.list(new SocDispatchEmpLessDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(socDispatchEmpLessDOList)) {
            SocDispatchEmpLessDO socDispatchEmpLessDO = socDispatchEmpLessDOList.get(0);
            socDispatchEmpLessQuery = socDispatchEmpLessDO.to(SocDispatchEmpLessQuery.class);
            if (socDispatchEmpLessDO.getSocEndDate() != null) {
                socDispatchEmpLessQuery.setSocEndDateStart(DateKit.getBeforeDay(socDispatchEmpLessDO.getSocEndDate(),-1));
                socDispatchEmpLessQuery.setSocEndDateEnd(DateKit.getBeforeDay(socDispatchEmpLessDO.getSocEndDate(),1));
            }
            if (socDispatchEmpLessDO.getFundEndDate() != null) {
                socDispatchEmpLessQuery.setFundEndDateStart(DateKit.getBeforeDay(socDispatchEmpLessDO.getFundEndDate(),-1));
                socDispatchEmpLessQuery.setFundEndDateEnd(DateKit.getBeforeDay(socDispatchEmpLessDO.getFundEndDate(),1));
            }
            if (socDispatchEmpLessDO.getQuitDate() != null) {
                socDispatchEmpLessQuery.setQuitDateStart(DateKit.getBeforeDay(socDispatchEmpLessDO.getQuitDate(),-1));
                socDispatchEmpLessQuery.setQuitDateEnd(DateKit.getBeforeDay(socDispatchEmpLessDO.getQuitDate(),1));
            }
        }
        return socDispatchEmpLessQuery;
    }

    /**
     * 保存示例
     * @return SocDispatchEmpLessVO
     */
    public SocDispatchEmpLessVO saveSocDispatchEmpLessExample(){
        SocDispatchEmpLessAddDTO addDTO = this.getSocDispatchEmpLessAddDTO();
        SocDispatchEmpLessVO socDispatchEmpLessVO = socDispatchEmpLessService.save(addDTO,buildTokenUser());
        return socDispatchEmpLessVO;
    }


}

